package com.example.lancooznbk.view.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.lancooznbk.R;
import com.example.lancooznbk.model.result.RecentStudyItemEntity;

import java.util.ArrayList;
import java.util.List;

import znbkListBj.activity.NotesListActivity;
import znbkListCtfd.activity.WrongTopicTutoringListActivity;
import znbkListNtxl.activity.TrainingDifficultProblemsListActivity;
import znbkListRdqh.activity.WeekAscensionListActivity;
import znbkListRdtz.activity.HeatPointExtensionListActivity;
import znbkListSc.activity.CollectionListActivity;
import znbkListXtfx.activity.SystemReviewListActivity;

/**
 * Author:    ZhuWenWu
 * Version    V1.0
 * Date:      2015/2/6  14:34.
 * Description:
 * Modification  History:
 * Date         	Author        		Version        	Description
 * -----------------------------------------------------------------------------------
 * 2015/2/6        ZhuWenWu            1.0                    1.0
 * Why & What is modified:
 */
public class HeaderBottomItemAdapter extends BaseMultipleItemAdapter {
//    private String[] mTitles;
    private static Context mContext;
    private List<RecentStudyItemEntity.LastAnswerBean> mList;

    public HeaderBottomItemAdapter(Context context) {
        super(context);
//        mTitles = context.getResources().getStringArray(R.array.titles);
        mList = new ArrayList<>();
        mHeaderCount = 1;
        mBottomCount = 1;
        mContext = context;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof HeaderViewHolder) {
        } else if (holder instanceof ContentViewHolder) {
            RecentStudyItemEntity.LastAnswerBean itemBean = mList.get(position);
            Log.e("==wwwwww==",position+"===="+itemBean.getTitle());
//            ((ContentViewHolder) holder).mTextView.setText(mTitles[position - mHeaderCount]);
        } else if (holder instanceof BottomViewHolder) {
        }
    }

    @Override
    public RecyclerView.ViewHolder onCreateHeaderView(ViewGroup parent) {
        return new HeaderViewHolder(mLayoutInflater.inflate(R.layout.rv_header, parent, false));
    }

    @Override
    public RecyclerView.ViewHolder onCreateContentView(ViewGroup parent) {
        return new ContentViewHolder(mLayoutInflater.inflate(R.layout.item_rv_zjxx, parent, false));
    }

    @Override
    public RecyclerView.ViewHolder onCreateBottomView(ViewGroup parent) {
        return new BottomViewHolder(mLayoutInflater.inflate(R.layout.rv_footer, parent, false));
    }

    @Override
    public int getContentItemCount() {
        return 5;
    }

    //内容 ViewHolder
    public static class ContentViewHolder extends RecyclerView.ViewHolder {
        private TextView textView;
        public ContentViewHolder(View itemView) {
            super(itemView);
            textView=(TextView)itemView.findViewById(R.id.tv_paperSummary22);
        }
    }
    //头部 ViewHolder
    public static class HeaderViewHolder extends RecyclerView.ViewHolder {
        public HeaderViewHolder(View itemView) {
            super(itemView);
            /*
           * 主界面学习模块按钮
           * 系统复习
           * */
            LinearLayout mLayoutSystemReview;
            mLayoutSystemReview = (LinearLayout) itemView.findViewById(R.id.layout_system_review);
            mLayoutSystemReview.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(mContext, SystemReviewListActivity.class);
                    mContext.startActivity(intent);
                }
            });

            /*
           * 主界面学习模块按钮
           * 弱点强化
           * */
            LinearLayout mLayoutWeekAscension;
            mLayoutWeekAscension = (LinearLayout) itemView.findViewById(R.id.layout_week_ascension);
            mLayoutWeekAscension.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(mContext, WeekAscensionListActivity.class);
                    mContext.startActivity(intent);
                }
            });

             /*
           * 主界面学习模块按钮
           * 难题训练
           * */
            LinearLayout mLayoutTrainingDifficultProblems;
            mLayoutTrainingDifficultProblems = (LinearLayout) itemView.findViewById(R.id.layout_training_difficult_problems);
            mLayoutTrainingDifficultProblems.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(mContext, TrainingDifficultProblemsListActivity.class);
                    mContext.startActivity(intent);
                }
            });

            /*
           * 主界面学习模块按钮
           * 错题辅导
           * */
            LinearLayout mLayoutHeatPointExtension;
            mLayoutHeatPointExtension = (LinearLayout) itemView.findViewById(R.id.layout_heat_point_extension);
            mLayoutHeatPointExtension.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(mContext, HeatPointExtensionListActivity.class);
                    mContext.startActivity(intent);
                }
            });

            /*
           * 主界面学习模块按钮
           * 错题辅导
           * */
            LinearLayout mLayoutWrongTopicTutoring;
            mLayoutWrongTopicTutoring = (LinearLayout) itemView.findViewById(R.id.layout_wrong_topic_tutoring);
            mLayoutWrongTopicTutoring.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(mContext, WrongTopicTutoringListActivity.class);
                    mContext.startActivity(intent);
                }
            });


        }
    }
    //底部 ViewHolder
    public static class BottomViewHolder extends RecyclerView.ViewHolder {
        public BottomViewHolder(View itemView) {
            super(itemView);

            /*
           * 主界面学习模块按钮
           * 笔记列表
           * */
            LinearLayout mLayoutNotes;
            mLayoutNotes = (LinearLayout) itemView.findViewById(R.id.layout_notes);
            mLayoutNotes.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(mContext, NotesListActivity.class);
                    mContext.startActivity(intent);
                }
            });

            /*
           * 主界面学习模块按钮
           * 收藏列表
           * */
            LinearLayout mLayoutCollection;
            mLayoutCollection = (LinearLayout) itemView.findViewById(R.id.layout_collection);
            mLayoutCollection.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(mContext, CollectionListActivity.class);
                    mContext.startActivity(intent);
                }
            });

        }
    }


    public void clearAndAdd(List<RecentStudyItemEntity.LastAnswerBean> data){
        mList.clear();
        mList.addAll(data);
        notifyDataSetChanged();
    }
    public void add(List<RecentStudyItemEntity.LastAnswerBean> data){
        mList.addAll(data);
        notifyItemRangeInserted(0,data.size());

    }

}
